<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>管理系统</title>
	<link rel="stylesheet" type="text/css" href="lib/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="lib/themes/icon.css">
<!--	<link rel="stylesheet" type="text/css" href="lib/demo/demo.css">-->
	<script type="text/javascript" src="lib/jquery.min.js"></script>
	<script type="text/javascript" src="lib/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="lib/locale/easyui-lang-zh_CN.js"></script>
	<script type="text/javascript" src="lib/jiekou.js"></script>
	<script type="text/javascript" src="lib/tools.js"></script>
</head>
    <body class="easyui-layout" style="background:url('1.jpg') no-repeat;background-size: cover;">
		<div id="w" class="easyui-window" title="登录" collapsible="false"
			minimizable="false" maximizable="false" icon="icon-save"
			style="width: 450px; height: 330px; padding: 30px; background: #fafafa;"
			data-options="closable:false,draggable:false">
			<form id="formlogin"> 
			<!-- menulogin -->
				<div style="margin-bottom: 20px">
					<input class="easyui-textbox" id="loginname" name="usercode"
						prompt="请输入用户名" iconWidth="28" 
						data-options="label:'用户名:',required:true"
						style="width: 300px; height: 34px; padding: 10px;">
				</div>
				<div style="margin-bottom: 20px">
					<input class="easyui-passwordbox" id="password" name="password"
						prompt="请输入密码" iconWidth="28"
						data-options="label:'密码:',required:true"
						style="width: 300px; height: 34px; padding: 10px">
				</div>
				<div style="margin-bottom: 20px">
					 <input class="easyui-textbox" id="icaptcha" name="captcha"
						prompt="验证码" iconWidth="28"
						data-options="label:'验证码:',required:true,missingMessage:''"
						style="width: 200px; height: 30px;">
					 <img id="codeimage" src="" captchaId="" style="width: 85px;height: 30px;"/>
				</div>  
			</form>
			<div style="text-align: center; padding: 5px 0">
				<a href="javascript:void(0)" id="login-submit-btn"
					class="easyui-linkbutton" style="width: 80px">登录</a>
<!--				<a href="javascript:void(0)" id="wechat-login-submit-btn"-->
<!--				class="easyui-linkbutton" style="width: 80px">微信扫码</a>-->
			</div>
		</div>
		<script>
			$(function() { 

				var capSuccess=function(res){
					var path=Network.domain+"/v1"+res.imageUrl;
					var captchaId=res.captchaId;
					$("#codeimage").attr('src',path);
					$("#codeimage").attr('captchaId',captchaId);
				};
				var capError=function(err){
					 Network.totast("验证码交易发送失败ERROR");
				};
				Network.get(jiekou.getCaptcha,{},capSuccess,capError);

			/*获取焦点*/
				$('#loginname').textbox('textbox').focus(); 
				/** 给登录按钮绑定点击事件  */
				$("#login-submit-btn").on("click", function() {
					
					/** 校验登录参数 ctrl+K */
					var loginname = $("#loginname").val();
					var password = $("#password").val();
					var code=$("#icaptcha").val();
					var captchId=$("#codeimage").attr('captchaId');
					
					//console.log(loginname,password,code,captchId);

					if(!loginname || !password || !code){
						$.messager.alert('提示','账号,密码,验证码,不能为空');
						return;
					}
                    var logindata={
						loginname:loginname,
						password:password,
						code:code,
						captchId:captchId
					};
					var loginSuccess=function(res){
						//业务逻辑
						if(res.code=='200'){
							localStorage.setItem('loginname', res.loginname); 
							localStorage.setItem('token', res.token); 
							localStorage.setItem('lastlogin', res.lastlogin);
							Tools.setCookie("mytoken",res.token,7*24*60*60);
							window.location.href='main.html';
							//发送消息
							Network.post(jiekou.sendMsg,{
								content:"login",
								to:res.loginname,
								userid:"xxx",
								msgtype:"1"
							},null,null);
							//发送消息end

						}else{
							Network.alert(res.msg,function(){
							window.location.href='index.html';});
							
							
						}
						//业务逻辑end

					};
					var loginError=function(err){
						Network.alert("请求失败");
						
					};
					Network.post(jiekou.login,logindata,loginSuccess,loginError);


				});
				
				
				/** 按了回车键 */
				$(document).keydown(function(event) {
					if (event.keyCode == 13) {
						$("#login-submit-btn").trigger("click");
					}
				})
			})
			function clearForm() {
				$('#formlogin').form('clear');
			}

			$("#wechat-login-submit-btn").click(function(){
				window.location.href="wechatlogin.html";
			});
		
		</script>
 
	
   
	</body>

 
</html>